/* I (David P Shenba) license this file to you under the Apache License, 
 * Version 2.0 (the "License"); you may not use this 
 * file except in compliance with the License.  You may 
 * obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.shenba.forms;

import java.util.ArrayList;

import org.apache.struts.action.ActionForm;
import org.shenba.beans.DemoBean;

/**
 * @author shenba
 *
 */
public class DemoForm extends ActionForm {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private ArrayList<DemoBean> demoBeans;
	/**
	 * @return the demoBeans
	 */
	public ArrayList<DemoBean> getDemoBeans() {
		return demoBeans;
	}
	/**
	 * @param demoBeans the demoBeans to set
	 */
	public void setDemoBeans(ArrayList<DemoBean> demoBeans) {
		this.demoBeans = demoBeans;
	}
	/**
	 * @param index
	 * @return
	 */
	public DemoBean getDemoBean(int index) {
		if(this.demoBeans == null) {
			this.demoBeans = new ArrayList<DemoBean>();
		}
		while (index >= this.demoBeans.size()) {
			this.demoBeans.add(new DemoBean());
		}
		return this.demoBeans.get(index);
	}
	/**
	 * @param index
	 * @param demoBean
	 */
	public void setDemoBean(int index, DemoBean demoBean) {
		if(this.demoBeans == null) {
			this.demoBeans = new ArrayList<DemoBean>();
		}
		if (index >= this.demoBeans.size()) {
			this.demoBeans.add(demoBean);
		}
		else {
			this.demoBeans.set(index, demoBean);
		}
	}
	/**
	 * @return
	 */
	public String getDemoBeansSize() {
		return (this.demoBeans == null) ? "0" : ""+this.demoBeans.size();
	}
	/**
	 * @param size
	 */
	public void setDemoBeansSize(String size) {
		this.demoBeans = new ArrayList<DemoBean>(Integer.parseInt(size));
	}
}
